/**两种使用方法：
 * 1）@JmsListener（在onMessage上注解）
 * 2）在Config中配置@Bean，并且在SimpleMessageListenerContainer或DefaultMessageListenerContainer中注入该bean。messageListenerContainer.setMessageListener
 */
package com.example.acitvemqspringbootdemo;

import org.springframework.jms.listener.SessionAwareMessageListener;

import javax.jms.*;

//@Component
public class MySessionAwareListener implements SessionAwareMessageListener<Message> {
    @Override
//    @JmsListener(destination = "send_reply_queue")
    public void onMessage(Message message, Session session) throws JMSException {
        System.out.println("[SessionAwareListener]received:" + ((TextMessage) message).getText());
        //通过session 创建  producer对象，再回送信息
        Destination replyQueueDestination=session.createQueue("reply_queue");
        System.out.println(message.getJMSReplyTo());
        MessageProducer producer = session.createProducer(replyQueueDestination);
        //创建一条消息
        Message replyMessage = session.createTextMessage("Reply from SessionAwareListener!");

        //调用发送
        producer.send(replyMessage);
    }
}
